********************************************************************
*                                                                  *
* Do Terrorists Get the Attention They Want?                       *
*                                                                  *
* Comparing Effects of Terrorism in Europe                         *
*                                                                  *
* Enzo Nussio, Tobias Böhmelt, and Vincenzo Bove                   *
*                                                                  *
* This Version: January 5, 2021                                    *
*                                                                  *
********************************************************************

********************
* Data Preparation *
********************

set matsize 11000
cd "C:\Users\tbohmelt\Dropbox\Eurobarometer\"
use "POQ data.dta", clear

************
* Figure 1 *
************

preserve
qui mixed miterrorism afterattack || surveyID: || nuts:, robust level(95)
keep if e(sample)
collapse miterrorism, by(cname year)
recode year (2013=1) (2015=2) (2017=3) (2018=4) (2019=5)
label define year 1 "London (2013)" 2 "Paris (2015)" 3 "Manchester (2017)" 4 "Carcasonne (2018)" 5 "Utrecht (2019)"
label values year year
xtline miterrorism, recast(scatter) msymbol(smcircle) i(cname) t(year) ytitle(Attention to Terrorism) ylabel(, angle(horizontal) format(%03.1f)) ttitle("") tlabel(1(1)5, valuelabel angle(vertical)) byopts(note("")) byopts(legend(off)) scheme(plotplain) aspectratio(1)
restore

*************************************************************
* Descriptive Statistics, Balance, and Oster Selection Test *
*************************************************************

preserve
qui mixed miterrorism afterattack || surveyID: || nuts:, robust level(95)
keep if e(sample)
sum miterrorism afterattack ln_fatalities age female rural unemployed education
collin afterattack ln_fatalities age female rural unemployed education
restore

preserve
drop if afterattack==.
bysort afterattack: summarize age female rural unemployed education
restore

foreach j of varlist age female rural unemployed education {
summ `j' if afterattack==1, d
local m1=r(mean)
local s1=r(Var)
summ `j' if afterattack==0, d
local m0=r(mean)
local s0=r(Var)
gen `j'x=(`m1'-`m0')/sqrt(`s1'+`s0')  
}
sum agex femalex ruralx unemployedx educationx
capture drop agex femalex ruralx unemployedx educationx

preserve
gen double n = _n/1000
gen double d = .
xtset units
gen double salience_beta = .
xtreg miterrorism afterattack age female rural unemployed education i.surveyID, fe robust
local rmax = e(r2_b)
foreach d in 0.5 0.75 1 1.25 1.5 1.75 2 2.25 2.5 2.75 3 3.25 3.5 3.75 4 4.25 4.5 4.75 5 {
		psacalc beta afterattack, delta(`d') rmax(0.0143)
		replace salience_beta = `r(beta)' if n == `d'
		replace d = `r(delta)' if n == `d'
			}
twoway (line salience_beta d,lpattern(dash) lcolor(black)), legend(off) scheme(plotplain) aspectratio(1)  plotregion(lcolor(none)) title("", size(medium)) xtitle("Ratio Selection on Unobservables" "to Selection on Observables",  size(medium)) xscale(titlegap(*7)) l1title("Treatment Effect", size(medium)) 
restore

**********************
* Main Effect Graphs *
**********************

preserve
mixed miterrorism afterattack || surveyID: || nuts:, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts:, robust level(95)
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts:, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts:, robust level(95)
replace afterattack=0 if daysafterattack==-4
replace afterattack=0 if daysafterattack==-5
replace afterattack=1 if daysafterattack==4
replace afterattack=1 if daysafterattack==5
mixed miterrorism afterattack || surveyID: || nuts:, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts:, robust level(95)
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts:, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts:, robust level(95)
replace afterattack=. if daysafterattack==-4
replace afterattack=. if daysafterattack==-5
replace afterattack=. if daysafterattack==4
replace afterattack=. if daysafterattack==5
replace afterattack=. if daysafterattack==-3
replace afterattack=. if daysafterattack==-2
replace afterattack=. if daysafterattack==3
replace afterattack=. if daysafterattack==2
mixed miterrorism afterattack || surveyID: || nuts:, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts:, robust level(95)
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts:, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts:, robust level(95)
restore

preserve
mixed miterrorism afterattack || surveyID: || nuts: if attackedcountry==1, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts: if attackedcountry==1, robust level(95)
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts: if attackedcountry==1, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts: if attackedcountry==1, robust level(95)
replace afterattack=0 if daysafterattack==-4
replace afterattack=0 if daysafterattack==-5
replace afterattack=1 if daysafterattack==4
replace afterattack=1 if daysafterattack==5
mixed miterrorism afterattack || surveyID: || nuts: if attackedcountry==1, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts: if attackedcountry==1, robust level(95)
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts: if attackedcountry==1, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts: if attackedcountry==1, robust level(95)
replace afterattack=. if daysafterattack==-4
replace afterattack=. if daysafterattack==-5
replace afterattack=. if daysafterattack==4
replace afterattack=. if daysafterattack==5
replace afterattack=. if daysafterattack==-3
replace afterattack=. if daysafterattack==-2
replace afterattack=. if daysafterattack==3
replace afterattack=. if daysafterattack==2
mixed miterrorism afterattack || surveyID: || nuts: if attackedcountry==1, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts: if attackedcountry==1, robust level(95)
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts: if attackedcountry==1 , robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts: if attackedcountry==1, robust level(95)
restore

preserve
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts:, robust level(95)
margins, dydx(afterattack) at(ln_fatalities=(0 4.919981)) vsquish
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts:, robust level(95)
margins, dydx(afterattack) at(ln_fatalities=(0 4.919981)) vsquish
replace afterattack=0 if daysafterattack==-4
replace afterattack=0 if daysafterattack==-5
replace afterattack=1 if daysafterattack==4
replace afterattack=1 if daysafterattack==5
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts:, robust level(95)
margins, dydx(afterattack) at(ln_fatalities=(0 4.919981)) vsquish
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts:, robust level(95)
margins, dydx(afterattack) at(ln_fatalities=(0 4.919981)) vsquish
replace afterattack=. if daysafterattack==-4
replace afterattack=. if daysafterattack==-5
replace afterattack=. if daysafterattack==4
replace afterattack=. if daysafterattack==5
replace afterattack=. if daysafterattack==-3
replace afterattack=. if daysafterattack==-2
replace afterattack=. if daysafterattack==3
replace afterattack=. if daysafterattack==2
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts:, robust level(95)
margins, dydx(afterattack) at(ln_fatalities=(0 4.919981)) vsquish
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts:, robust level(95)
margins, dydx(afterattack) at(ln_fatalities=(0 4.919981)) vsquish
restore

use "C:\Users\tbohmelt\Dropbox\Eurobarometer\Main Effects Graph.dta", clear
twoway (scatter var1 var2 if var5=="Without C" & var7=="", mcolor(black) msymbol(smcircle)) (rcap var3 var4 var1 if var5=="Without C" & var7=="", lcolor(black) lpattern(dash) horizontal msize(zero)) (scatter var1 var2 if var5=="C" & var7=="", msymbol(smcircle)) (rcap var3 var4 var1 if var5=="C" & var7=="", lpattern(dash) horizontal msize(zero)), yscale(off) ylabel(0(0.5)3.5) xtitle(Change in Probability of Attention to Terrorism) xlabel(, format(%3.2f)) legend(off) scheme(plotplain) aspectratio(1)
twoway (scatter var1 var2 if var5=="Without C" & var7=="l", mcolor(black) msymbol(smcircle)) (rcap var3 var4 var1 if var5=="Without C" & var7=="l", lcolor(black) lpattern(dash) horizontal msize(zero)) (scatter var1 var2 if var5=="Without C" & var7=="h", mcolor(black) msymbol(smcircle)) (rcap var3 var4 var1 if var5=="Without C" & var7=="h", lcolor(black) lpattern(dash) horizontal msize(zero)) (scatter var1 var2 if var5=="C" & var7=="h", msymbol(smcircle)) (rcap var3 var4 var1 if var5=="C" & var7=="h", lpattern(dash) horizontal msize(zero)) (scatter var1 var2 if var5=="C" & var7=="l", msymbol(smcircle)) (rcap var3 var4 var1 if var5=="C" & var7=="l", lpattern(dash) horizontal msize(zero)), yscale(off) xtitle(Change in Probability of Attention to Terrorism) xlabel(, format(%3.2f)) legend(off) scheme(plotplain) aspectratio(1)

*********************
* Loop Over Surveys *
*********************

forval i = 1(1)5{
		use "EB full data.dta", clear
		gen sample=1 if surveyID==5689 
		replace sample=1 if surveyID==6643
		replace sample=1 if surveyID==6863
		replace sample=1 if surveyID==6963
		replace sample=1 if surveyID==7562
		drop if sample==. // keeps only Islamist attacks in our sample period (2013-2019)
		encode nuts, gen(units)
		gen afterattack=0 if daysafterattack==-1
		replace afterattack=0 if daysafterattack==-2
		replace afterattack=0 if daysafterattack==-3
		replace afterattack=1 if daysafterattack==.
		replace afterattack=1 if daysafterattack==1
		replace afterattack=1 if daysafterattack==2
		replace afterattack=1 if daysafterattack==3
		qui mixed miterrorism afterattack || surveyID: || nuts:, robust level(95)
		keep if e(sample)
		sort surveyID
		by surveyID: gen newid = 1 if _n==1
		replace newid = sum(newid)
		replace newid = . if missing(surveyID)
		mixed miterrorism afterattack || nuts: if newid==`i', robust level(95)
		}

forval i = 1(1)5{
		use "EB full data.dta", clear
		gen attackedcountry = 0
		replace attackedcountry = 1 if Countryofattack==country
		gen sample=1 if surveyID==5689
		replace sample=1 if surveyID==6643
		replace sample=1 if surveyID==6863
		replace sample=1 if surveyID==6963
		replace sample=1 if surveyID==7562
		drop if sample==. // keeps only Islamist attacks in our sample period (2013-2019)
		encode nuts, gen(units)
		gen afterattack=0 if daysafterattack==-1
		replace afterattack=0 if daysafterattack==-2
		replace afterattack=0 if daysafterattack==-3
		replace afterattack=1 if daysafterattack==.
		replace afterattack=1 if daysafterattack==1
		replace afterattack=1 if daysafterattack==2
		replace afterattack=1 if daysafterattack==3
		qui mixed miterrorism afterattack || surveyID: || nuts:, robust level(95)
		keep if e(sample)
		sort surveyID
		by surveyID: gen newid = 1 if _n==1
		replace newid = sum(newid)
		replace newid = . if missing(surveyID)
		mixed miterrorism afterattack || nuts: if newid==`i' & attackedcountry==1, robust level(95)
		}
		
use "C:\Users\tbohmelt\Dropbox\Eurobarometer\Loop\Effects.dta", clear
label define year 9 "London (2013)" 2 "" 1 "Paris (2015)" 4 "" 3 "Manchester (2017)" 6 "" 5 "Carcasonne (2018)" 8 "" 7 "Utrecht (2019)" 10 ""
label values year year
twoway (scatter coeff year if var6=="Own", mcolor(black) msymbol(smcircle)) (rcap lb ub year if var6=="Own", lcolor(black) lpattern(dash) msize(zero)) (scatter coeff year if var6=="", mcolor(black) msymbol(smcircle)) (rcap lb ub year if var6=="", lcolor(black) lpattern(dash) msize(zero)), ytitle(Change in Probability of Attention to Terrorism) yline(0) ylabel(0(0.05)0.35, format(%3.2f)) xtitle("") xlabel(1(1)10, valuelabel angle(vertical)) legend(off) scheme(plotplain) aspectratio(1)

*********************
* Robustness Checks *
*********************

use "EB full data.dta", clear
gen sample=1 if surveyID==5689 
replace sample=1 if surveyID==6643
replace sample=1 if surveyID==6863
replace sample=1 if surveyID==6963
replace sample=1 if surveyID==7562
drop if sample==. // keeps only Islamist attacks in our sample period (2013-2019)
gen contig=0
replace contig=1 if contiguity==1
replace contig=1 if contiguity==2
replace contig=1 if contiguity==3
encode nuts, gen(units)
gen attackedcountry = 0
replace attackedcountry = 1 if Countryofattack==country
gen afterattack=0 if daysafterattack==-1
replace afterattack=0 if daysafterattack==-2
replace afterattack=0 if daysafterattack==-3
replace afterattack=1 if daysafterattack==.
replace afterattack=1 if daysafterattack==1
replace afterattack=1 if daysafterattack==2
replace afterattack=1 if daysafterattack==3
gen ln_fatalities=ln(fatalities)

preserve
gen casualties=fatalities
replace casualties=(413+137) if casualties==137
replace casualties=(23+119) if casualties==23
replace casualties=10 if casualties==3
replace casualties=20 if casualties==5
replace casualties=ln(casualties)
mixed miterrorism i.afterattack##c.casualties age female rural unemployed education || surveyID: || nuts:, robust level(95)
replace afterattack=0 if daysafterattack==-4
replace afterattack=0 if daysafterattack==-5
replace afterattack=1 if daysafterattack==4
replace afterattack=1 if daysafterattack==5
mixed miterrorism i.afterattack##c.casualties age female rural unemployed education || surveyID: || nuts:, robust level(95)
replace afterattack=. if daysafterattack==-4
replace afterattack=. if daysafterattack==-5
replace afterattack=. if daysafterattack==4
replace afterattack=. if daysafterattack==5
replace afterattack=. if daysafterattack==-3
replace afterattack=. if daysafterattack==-2
replace afterattack=. if daysafterattack==3
replace afterattack=. if daysafterattack==2
mixed miterrorism i.afterattack##c.casualties age female rural unemployed education || surveyID: || nuts:, robust level(95)
restore

logit miterrorism afterattack age female rural unemployed education i.units i.surveyID, robust level(95)
logit miterrorism afterattack##c.ln_fatalities age female rural unemployed education i.units i.surveyID, robust level(95)

mixed miterrorism i.afterattack##i.contig age female rural unemployed education || surveyID: || nuts:, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities##i.contig age female rural unemployed education || surveyID: || nuts:, robust level(95)

mixed trustineucentralbank afterattack age female rural unemployed education || surveyID: || nuts:, robust level(95)
mixed trustineucentralbank afterattack##c.ln_fatalities  age female rural unemployed education || surveyID: || nuts:, robust level(95)

use "EB full data.dta", clear
gen sample=1 if surveyID==5689 
replace sample=1 if surveyID==6643
replace sample=1 if surveyID==6863
replace sample=1 if surveyID==6963
replace sample=1 if surveyID==7562
drop if sample==. // keeps only Islamist attacks in our sample period (2013-2019)
gen afterattack=1 if daysafterattack==-1
replace afterattack=1 if daysafterattack==-2
replace afterattack=0 if daysafterattack==-3
replace afterattack=0 if daysafterattack==.
replace afterattack=0 if daysafterattack==1
replace afterattack=0 if daysafterattack==2
replace afterattack=0 if daysafterattack==3
gen ln_fatalities=ln(fatalities)
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts:, robust level(95)
mixed miterrorism afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts:, robust level(95)

use "EB full data.dta", clear
gen sample=1 if surveyID==5689 
replace sample=1 if surveyID==6643
replace sample=1 if surveyID==6863
replace sample=1 if surveyID==6963
replace sample=1 if surveyID==7562
drop if sample==. // keeps only Islamist attacks in our sample period (2013-2019)
gen contig=0
replace contig=1 if contiguity==1
replace contig=1 if contiguity==2
replace contig=1 if contiguity==3
encode nuts, gen(units)
gen attackedcountry = 0
replace attackedcountry = 1 if Countryofattack==country
gen ln_fatalities=ln(fatalities)

preserve
gen afterattack=0 if daysafterattack==-1
replace afterattack=0 if daysafterattack==-2
replace afterattack=0 if daysafterattack==-3
replace afterattack=1 if daysafterattack==0
replace afterattack=1 if daysafterattack==1
replace afterattack=1 if daysafterattack==2
replace afterattack=1 if daysafterattack==3
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts:, robust level(95)
mixed miterrorism afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts:, robust level(95)
restore

preserve
gen afterattack=0 if daysafterattack==-1
replace afterattack=0 if daysafterattack==-2
replace afterattack=0 if daysafterattack==-3
replace afterattack=1 if daysafterattack==.
replace afterattack=1 if daysafterattack==1
replace afterattack=1 if daysafterattack==2
replace afterattack=1 if daysafterattack==3
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts: if attackedcountry==1, robust level(95)
mixed miterrorism afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts: if attackedcountry==1, robust level(95)
restore

use "EB full data.dta", clear
gen sample=1 if surveyID==4056 
replace sample=1 if surveyID==5689
replace sample=1 if surveyID==6643
replace sample=1 if surveyID==6863
replace sample=1 if surveyID==6963
replace sample=1 if surveyID==7562
drop if sample==. // keeps only Islamist attacks in our sample period (2004-2019)
gen contig=0
replace contig=1 if contiguity==1
replace contig=1 if contiguity==2
replace contig=1 if contiguity==3
encode nuts, gen(units)
gen attackedcountry = 0
replace attackedcountry = 1 if Countryofattack==country
gen ln_fatalities=ln(fatalities)
gen afterattack=0 if daysafterattack==-1
replace afterattack=0 if daysafterattack==-2
replace afterattack=0 if daysafterattack==-3
replace afterattack=1 if daysafterattack==.
replace afterattack=1 if daysafterattack==1
replace afterattack=1 if daysafterattack==2
replace afterattack=1 if daysafterattack==3
preserve
mixed miterrorism afterattack || surveyID: || nuts:, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts:, robust level(95)
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts:, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts:, robust level(95)
replace afterattack=0 if daysafterattack==-4
replace afterattack=0 if daysafterattack==-5
replace afterattack=1 if daysafterattack==4
replace afterattack=1 if daysafterattack==5
mixed miterrorism afterattack || surveyID: || nuts:, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts:, robust level(95)
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts:, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts:, robust level(95)
replace afterattack=. if daysafterattack==-4
replace afterattack=. if daysafterattack==-5
replace afterattack=. if daysafterattack==4
replace afterattack=. if daysafterattack==5
replace afterattack=. if daysafterattack==-3
replace afterattack=. if daysafterattack==-2
replace afterattack=. if daysafterattack==3
replace afterattack=. if daysafterattack==2
mixed miterrorism afterattack || surveyID: || nuts:, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts:, robust level(95)
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts:, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts:, robust level(95)
restore

preserve
mixed miterrorism afterattack || surveyID: || nuts: if attackedcountry!=1, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts: if attackedcountry!=1, robust level(95)
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts: if attackedcountry!=1, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts: if attackedcountry!=1, robust level(95)
replace afterattack=0 if daysafterattack==-4
replace afterattack=0 if daysafterattack==-5
replace afterattack=1 if daysafterattack==4
replace afterattack=1 if daysafterattack==5
mixed miterrorism afterattack || surveyID: || nuts: if attackedcountry!=1, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts: if attackedcountry!=1, robust level(95)
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts: if attackedcountry!=1, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts: if attackedcountry!=1, robust level(95)
replace afterattack=. if daysafterattack==-4
replace afterattack=. if daysafterattack==-5
replace afterattack=. if daysafterattack==4
replace afterattack=. if daysafterattack==5
replace afterattack=. if daysafterattack==-3
replace afterattack=. if daysafterattack==-2
replace afterattack=. if daysafterattack==3
replace afterattack=. if daysafterattack==2
mixed miterrorism afterattack || surveyID: || nuts: if attackedcountry!=1, robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities || surveyID: || nuts: if attackedcountry!=1, robust level(95)
mixed miterrorism afterattack age female rural unemployed education || surveyID: || nuts: if attackedcountry!=1 , robust level(95)
mixed miterrorism i.afterattack##c.ln_fatalities age female rural unemployed education || surveyID: || nuts: if attackedcountry!=1, robust level(95)
restore
